<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1200px" append-to-body>
        <el-form :model="queryParams" ref="queryForm" inline label-width="80px">
            <el-form-item label="店铺" prop="shop_id">
                <el-select v-model="queryParams.shop_id" placeholder="请选择店铺" clearable size="small" style="width: 240px" multiple filterable collapse-tags>
                    <el-option v-for="(dict, index) in shopList" :key="index" :label="dict.shop_name" :value="dict.shop_id" />
                </el-select>
            </el-form-item>

            <el-form-item label="付款时间" prop="createtime">
                <el-date-picker v-model="queryParams.createtime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px">
                </el-date-picker>
            </el-form-item>    

            <el-form-item label="维度" prop="Dimension">
                <el-radio-group v-model="queryParams.Dimension" @change="changeDimension">
                    <el-radio-button :label="1">天</el-radio-button>
                    <el-radio-button :label="2">周</el-radio-button>
                    <el-radio-button :label="3">月</el-radio-button>
                </el-radio-group>
            </el-form-item>

            <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="getDetail">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        <el-row type="flex">
            <el-col :span="24">
                <SpuSalesRanking idName="spuSalesRankingChat" :chartData="chatList" :height="480" label="quantity" />
            </el-col>
        </el-row>
    </el-dialog>
</template>

<script>
import { StoreDisputeRate} from '@/api/order'
import { getShopList } from '@/api/shop'
import SpuSalesRanking from './SpuSalesRanking'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'SpuSalesRankingDialog',
    components: {
        SpuSalesRanking,
    },
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            shopList: [],
            loading: false,
            chatList: [],
            queryParams: {
                Dimension : 1,
            }
        }
    },
    computed: {
        title() {
            return `店铺争议率`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    async created() {
        this.loading = true
        try {
            const [shopData] = await Promise.all([getShopList()])
            this.shopList = shopData?.data?.list ?? []
        } catch (error) {
            this.loading = false
            console.log(error)
        }
    },
    watch: {
        params: {
            handler(val) {
                if (val) {
                    this.queryParams = Object.assign({}, this.queryParams, val)
                }
            },
            immediate: true,
            deep: true,
        },
    },
    mounted() {
        this.getDetail()
    },
    methods: {
        changeDimension() {
            this.getDetail()
        },
        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')
            this.getDetail()
        },
        getDetail() {
            this.loading = true
            const qyparams = { ...this.queryParams }
            if(qyparams.createtime && qyparams.createtime.length==2) {
                qyparams.createtime = [parseTime(qyparams.createtime[0], 'y-m-d'), parseTime(qyparams.createtime[1], 'y-m-d')]; 
            }
            StoreDisputeRate(qyparams)
                .then(res => {
                    this.chatList = res.data ?? []
                })
                .finally(() => {
                    this.loading = false
                })
        },
    },
}
</script>

<style></style>
